<%@ include file="/WEB-INF/views/commons/header.jsp" %>
<%@ include file="/WEB-INF/views/commons/menu.jsp" %>
<div id="boddy" name="boddy" style="position: absolute; cursor:wait; visibility:hidden; background-color:white; text-align: center; display:box; box-pack:center; box-align:center;" >
	<img alt="" src="<pc:GetUrlUriTags value="/resources/image/icons/waiting-wheel-300x300.gif" />" style="text-decoration: none; border-width: 0px; width: 100px; height: 100px;">
</div>
<!-- START BODY -->
<link href="<pc:GetUrlUriTags value="/resources/css/search/search.css" />" media="screen" rel="stylesheet" type="text/css" />
<table class="topSubject" width="100%" border="0">  
  <tr>
    <td height="30px"  width="34px">
    	<img alt="" src="<pc:GetUrlUriTags value="/resources/image/icons/png_apps/32x32/cloud-1.png" />" style="text-decoration: none; border-width: 0px;">
    </td>
    <td height="30px" align="left">
    	<div>
			<strong><a href="<pc:GetUrlUriTags value="/fi/outbound/rental/depositreturn/backlogs/index" />" class="topSubjectText">
			&nbsp;Interface Pending Deposit Return.
			</a></strong>
		</div>
    </td>
  </tr>
</table>

<div class="topSubject" style="width: 100%; height:auto; vertical-align: middle; text-align: center;">
<form:form id="ObjectForm-form"  modelattribute="ObjectForm" commandName="ObjectForm" method="post" action="search" >
<table class="topSubject" style="display: inline-block;">
	<tr>
		<td style="vertical-align: middle; text-align:center; width: 150px;">
			<div class="topLeftSearchCriteria">Search by Criteria</div>
		</td>
		<td>
			<div style="border-width: 1px; border-color: #D8D8D8; border-style: solid; padding: 5px; ">			
				<table width="100%" class="topSubject">
				  <tr>		
				  	<!-- 	  	
				  	<td>
						<label class="labelSearch">Company</label>
						<form:input path="company" cssClass="txtSearch"  autofocus="autofocus"/>
						<form:errors path="company" cssClass="error"></form:errors>
				  	</td>					
				  	<td>
						<label class="labelSearch">Project</label>
						<form:input path="project" cssClass="txtSearch"  autofocus="autofocus"/>
						<form:errors path="project" cssClass="error"></form:errors>
				  	</td>
				  	<td>
						<label class="labelSearch">DocumentNo</label>
						<form:input path="documentNo" cssClass="txtSearch"  autofocus="autofocus"/>
						<form:errors path="documentNo" cssClass="error"></form:errors>
				  	</td>
				  	<td>
						<label class="labelSearch">Isstaging</label>
						<form:input path="syncIsstaging" cssClass="txtSearch"  autofocus="autofocus"/>
						<form:errors path="syncIsstaging" cssClass="error"></form:errors>
				  	</td>
				  </tr>
				  <tr>		
				   <td>
						<label class="labelSearch">Issync</label>
						<form:input path="syncIssync" cssClass="txtSearch"  autofocus="autofocus"/>
						<form:errors path="syncIssync" cssClass="error"></form:errors>
				   </td>
				    
				  	<td>
						<label class="labelSearch">Status</label>
						<form:input path="status" cssClass="txtSearch"  autofocus="autofocus"/>
						<form:errors path="status" cssClass="error"></form:errors>
				  	</td>				  	
				  	<td>
						<label class="labelSearch">Ref Document No</label>
						<form:input path="refDocNo" cssClass="txtSearch"  autofocus="autofocus"/>
						<form:errors path="refDocNo" cssClass="error"></form:errors>
				  	</td>	
				  	-->			
				  	<td>
				  		<label class="labelSearch">Max Result</label>
						<form:input path="maxResult" cssClass="txtSearch"  autofocus="autofocus"/>
						<form:errors path="maxResult" cssClass="error"></form:errors>
				  	</td>
				  </tr>
				</table>			
			</div>
		</td>
		<td>
			<input id="btnSearch" type="submit" style="margin-left: 10px;" class="button round blue image-right ic-right-arrow" value="Search" />
			<input type="hidden" id="AUTHEN_KEY" value="<pc:AppHosts code="AUTHEN_KEY" isActive="Y" client="NSTDA" />">
			<input type="hidden" id="PMS_APPS_INTERFACE_HOST_hiden" value="<pc:AppHosts code="PMS_APPS_INTERFACE_HOST" isActive="Y" client="NSTDA" />">
		</td>
	</tr>
</table>
</form:form>

<link href="<pc:GetUrlUriTags value="/resources/kendoui.web.2013.2.716/content/shared/styles/examples-offline.css" />" rel="stylesheet" />
<link href="<pc:GetUrlUriTags value="/resources/kendoui.web.2013.2.716/styles/kendo.common.css" />" rel="stylesheet" />
<link href="<pc:GetUrlUriTags value="/resources/kendoui.web.2013.2.716/styles/kendo.default.css" />" rel="stylesheet" />
<script src="<pc:GetUrlUriTags value="/resources/kendoui.web.2013.2.716/js/jquery.min.js" />" ></script>
<script src="<pc:GetUrlUriTags value="/resources/kendoui.web.2013.2.716/js/kendo.web.js" />" ></script>
<script src="<pc:GetUrlUriTags value="/resources/kendoui.web.2013.2.716/content/shared/js/console.js" />" ></script>
	<div id="example" class="k-content">
            <div id="grid"></div>
            <style>
            		.center{
            		
	            		width:350px;
						height:100px;
						border:1px solid black;
						
						/* Internet Explorer 10 */
						display:-ms-flexbox;
						-ms-flex-pack:center;
						-ms-flex-align:center;
						
						/* Firefox */
						display:-moz-box;
						-moz-box-pack:center;
						-moz-box-align:center;
						
						/* Safari, Opera, and Chrome */
						display:-webkit-box;
						-webkit-box-pack:center;
						-webkit-box-align:center;
						
						/* W3C */
						display:box;
						box-pack:center;
						box-align:center;
            		}
            </style>
            <script>				
				
				$(document).ready(function() {
					fnSearch();
					//alert("already !!!");			 	
                });
                				
            	function fnSearch(){
            		/*
                	var param_p = "company=" + $("#company").val();
                	param_p += "&project=" + $("#project").val();
                	param_p += "&documentNo=" + $("#documentNo").val();
                	param_p += "&voucherType=";
                	param_p += "&syncIsstaging=" + $("#syncIsstaging").val();
                	param_p += "&syncIssync=" + $("#syncIssync").val();
                	param_p += "&status=" + $("#status").val();
                	param_p += "&refDocNo=" + $("#refDocNo").val();
                	param_p += "&maxResult=" + $("#maxResult").val();
                	*/
                	var param_p = $("#maxResult").val();
                	var dataSource_p = getDataSource(param_p);
					GridBuilding(dataSource_p);
					adjuestScreen();	
                }

                function getDataSource(param) {				
					var url_p = "<pc:GetUrlUriTags value='/fi/outbound/rental/depositreturn/backlogs/search/json' />";
					if(param != null)
						url_p += "?" + param;
						
                	var  dataSource = new kendo.data.DataSource({
                         type: "json",
                         transport: {
                         	read: {
                             		url : url_p,
                             		dataType: "json"
                            }
                         },
                         schema: {
                             model: {
                                 fields: {
                                	 
                                	 id: { type: "string" },
                                	 company: { type: "string" },
                                	 project: { type: "string" },
                                	 documentNo: { type: "string" },                                	 
                                	 status: { type: "string" },
                                	 syncIsstaging: { type: "string" },
                                	 syncIssync: { type: "string" }
                                 }
                             }
                         },
                         pageSize: 200,
                         serverPaging: false,
                         serverFiltering: false,
                         serverSorting: false
                     });
					 return dataSource;
                }
				
				function GridBuilding(dataSource_p){
					$("#grid").kendoGrid({
                        dataSource: dataSource_p,
                        height: 430,                        
                        scrollable: true,
                        sortable: true,
                        filterable: true,
                        reorderable: true,
                        resizable: true,
                        pageable: {
                        	refresh: true,
                            input: true,
                            numeric: false
                        },
                        columns: [
								{ field:"id", title:"Id", width: 180, filterable: true },
								{  
                              	  title: "",
                              	  template: "<input type=\"button\" style=\"height: 30px;width: 80px;\" onclick=\"submitData('#=company#', '#=project#', '#=documentNo#');\" value=\"RE-SEND\">"
                              	  ,filterable: false ,width: 100
                            	},
								{ field:"company", title: "Company", width: 180, filterable: true },								
								{ field:"project", title: "Project", width: 180, filterable: true },
								{ field:"documentNo", title:"Document No" , width: 180, filterable: true },
								{ field:"status" , width: 180, filterable: true },
								{ field:"syncIsstaging" , width: 180, filterable: true },
								{ field:"syncIssync" , width: 180, filterable: true }
                        ]
                    });
				} 
				
				function submitData(company, project, documentNo){
					
	            	var host = $("#PMS_APPS_INTERFACE_HOST_hiden").val();
	            	var key = $("#AUTHEN_KEY").val();
	            	
	            	var url = "/fi/outbound/rental/deposit/return/interface";
	            	var param = "&processAction=RE-SEND";
	            	param += "&company=" + company;
	            	param += "&project=" + project;
	            	param += "&documentNo=" + documentNo;
	            	var urlTxt = (host + url + "?" + key + param);
	            	alert(urlTxt);
	            	try{
	            		var r=window.confirm("Are you sure ?");
						if (r==true)
							{

		      					$('#boddy').width($(window).width());
		            		  	$('#boddy').height($(window).height());
		            		  	
								$('#grid').css("visibility","hidden");
								$('#boddy').css("visibility","visible");
								
								$.ajax({
				            	    type: "GET",
				            	    url: urlTxt,
				            	    dataType: "xml",
				            	    success: function(xml){
				            	    $(xml).find('SapResultBack').each(function(){
				            	    	
				            	      //var module = $(this).find('module').text();
				            	      //var msgcode = $(this).find('msgcode').text();
				            	      var msgDescription = $(this).find('msgDescription').text();
				            	      //var extRefNo = $(this).find('extRefNo').text();
				            	      //var extRefKey = $(this).find('extRefKey').text();
				            	      //var instanceNo = $(this).find('instanceNo').text();
				            	      //var returnDateTime = $(this).find('returnDateTime').text();
				            		  
				            	      $('#grid').css("visibility","visible");
				            	      $("#boddy").css("visibility","hidden");
				            	      alert(msgDescription);
				            	      
				            	    });
				            	  },
				            	  error: function() {
				            		 $('#grid').css("visibility","visible");
				            		 $("#boddy").css("visibility","hidden");
				            	    alert("An error occurred while processing XML file.");				            	    
				            	  }
				            	  });
							}
            		}
            		catch(e){
            		 	alert("An error has occurred: "+ e.message)
            		}
            		finally{
            			
            		}
				}
            </script>
        </div>

</div>

<!-- END BODY -->
<%@ include file="/WEB-INF/views/commons/footer.jsp" %>